/*
 * Yuru be simple
 */

package udpserver;

import java.io.*;
import java.net.*;

/**
 *
 * @author makkalot
 */
public class SimpleUdpServer {

    
  public final static int DEFAULT_PORT = 9999;//where to bind
  public final static int MAX_PACKET_SIZE = 65507;//yep the packet size 

  public static void main(String[] args) {

    int port = DEFAULT_PORT;
    byte[] buffer = new byte[MAX_PACKET_SIZE]; //we send binary

    try {
      //start listening on the port someone to send you something  
      DatagramSocket server = new DatagramSocket(port);
      System.out.println("Ben tatar ramazan bu oyunu bu portta bozarim :"+port);
      //we will get data from here
      DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
      
      while (true) {
        try {
          //oldugu surece recieve
          server.receive(packet);
          String s = new String(packet.getData(), 0, packet.getLength());
          
          System.out.println(packet.getAddress() + " at port " 
           + packet.getPort() + " says " + s);
          // reset the length for the next packet
          packet.setLength(buffer.length);
        }
        catch (IOException ex) {
          System.err.println(ex);
        }      
      System.out.println("Size dedim oyun bozuldu ...");
      } // end while
      
      
    }  // end try
    catch (SocketException  ex) {
      System.err.println(ex);
    }  // end catch

  }  // end main
    
}
